<template>
  <el-form >
    <el-form-item label-width="120px" label="申请退单原因" :required="true">
      <el-input width="100%"  type="textarea" v-model="modReason" placeholder="目前退单由服开发起，此功能一次开发只测试功能，校验规则暂未添加"></el-input>
    </el-form-item>
    <el-form-item class="btnDir">
      <el-button @click="onSubmit" type="primary">退 单</el-button>
      <el-button @click="onCancel" type="info">取 消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import requestUtil from '@/utils/requestEnc';
import CustOrderService from "@/api/order/CustOrderService";
import OrderService from "@/api/order/OrderService";

export default {
  components: {
		requestUtil,
		CustOrderService,
    OrderService
  },
  async mounted(){
    
    
    if(this.CTOInfo.length > 0){
      var orderItemIds="";

      for(var i=0;i<this.CTOInfo.length;i++){
         if(i==0){
           orderItemIds += this.CTOInfo[i].orderItemId;
         }else{
            orderItemIds += ","+this.CTOInfo[i].orderItemId;
         }
      }
      this.orderItemIds = orderItemIds;
    }
  },

  props:{
	  	ODKInfo: {
			type: Object,
			default: () => {
				return {};
			},
		},
		CTOInfo: {
			type: Array,
			default: () => {
				return [];
			},
		},

  },
  data() {
    return {
    modReason:"",
    orderItemIds:""
	  }
  },
  methods: {
    // 提交
    async onSubmit(param){

      
      var backComment=this.modReason;
      if(backComment=='' || backComment=='undefined'){
          this.$confirm("申请退单原因不能为空!", "提示", {
            confirmButtonText: "确定",
            showCancelButton: false,
            type: "warn",
            center: true
          });
          return ;
      }
      var orderItemIds=this.orderItemIds;
      var userId=this.CTOInfo[0].createStaff;
      var custSoNumber=this.CTOInfo[0].custSoNumber;
      var custId=this.CTOInfo[0].custId;
      const res =await OrderService.applyBackOrder({orderItemIds,backComment,userId,custSoNumber,custId});

      if (res.code == 200) {
          this.$confirm("申请退单成功", "提示", {
            confirmButtonText: "确定",
            showCancelButton: false,
            type: "warn",
            center: true
          }).then(() => {
            this.$emit('update:show',false);
          });
      }else{
        this.$confirm(res.meta.resultMsg, "提示", {
            confirmButtonText: "确定",
            showCancelButton: false,
            type: "warn",
            center: true
          });
      }
    },
    onCancel(){
      this.$emit('update:show',false);
    },


  }
}
</script>
<style>
.el-form--inline .el-form-item {
  display: inline-flex;
  margin-right: 0.1rem;
  vertical-align: top;
  width: 42%;
}

.el-form-item__label {
  width: 94px;
}
.btnDir {
  margin-left: 36%;
  margin-top: 19px;
}
.el-table--enable-row-transition{
  margin-bottom: 20px;
}
</style>

